package com.chacha.framework.dasboard.tools;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

/**
 * @author rachmat_doni@smltech.co.id
 * 
 */

public class DataJsonSingleSeries {

	private List<String> properties;
	private List<String> datas;
	
	public DataJsonSingleSeries(List<String> properties){
		this.properties = properties;
		datas = new ArrayList<String>();
	}

	public void addData(String label, String value, String link) {
		StringBuilder data = new StringBuilder("{" + " \"label\": \"" + label + "\", " + " \"value\": \"" + value + "\" ");
		if(link!=null&&!link.isEmpty())
			data.append(", \"link\": \"" + link + "\" "); 
		data.append("} ");
		
		datas.add(data.toString());
	}

	public String getJSONData(){
		StringBuilder initData = new StringBuilder("{   \"chart\": {"); 	
		StringBuilder data = new StringBuilder(" \"data\": [");
		
		for(String prop: properties){
			initData.append(prop +", ");
		}
		initData.delete(initData.length()-2, initData.length());
		initData.append("}, ");
		
		for(String dt: datas){
			data.append(dt + ", ");
		}
		
		initData.append(StringUtils.removeEnd(data.toString(), ", ") + "]"+ "}");
		
		return initData.toString();
	}
}
